package com.godGuang.mine.controller;

/**
 * @Author The future is full of hope
 * @CreateTime 2024/1/8 0008 11:47
 * @PackageName:com.godGuang.mine.controller
 * @ClassName: MineController
 */

import com.godGuang.common.core.domain.Result;
import com.godGuang.mine.domain.*;
import com.godGuang.mine.domain.Req.ReqEvaluate;
import com.godGuang.mine.domain.Req.ReqTask;
import com.godGuang.mine.service.MineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 个人服务接口
 */

@RestController
@RequestMapping("/mine")
@Slf4j
public class MineController {

    @Autowired
    private MineService mineService;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;


    /**
     * 首页目录
     *
     * @return
     */
    @GetMapping("/queryCatalogueName")
    public Result<List<Catalogue>> queryCatalogueName() {
        long l = System.currentTimeMillis();
        log.info("功能名称:{首页目录},请求方法:{},请求URL:{}",
                request.getMethod(), request.getRequestURL());
        List<Catalogue> queryCatalogueName = mineService.queryCatalogueName();
        long l1 = System.currentTimeMillis();
        log.info("功能名称:{首页目录},请求方法:{},请求URL:{},响应结果:{},接口耗时:{}",
                request.getMethod(), request.getRequestURL(), queryCatalogueName, l1 - l + "毫秒");
        return Result.success(queryCatalogueName);
    }

    /**
     * 根据目录查询病症
     *
     * @return
     */
    @PostMapping("/queryDiseaseNameByCatalogueId/{catalogueId}")
    public Result<List<Disease>> queryDiseaseNameByCatalogueId(@PathVariable Integer catalogueId) {
        long l = System.currentTimeMillis();
        log.info("功能名称:{根据目录查询病症},请求方法:{},请求URL:{}",
                request.getMethod(), request.getRequestURL());
        List<Disease> queryDiseaseNameByCatalogueId = mineService.queryDiseaseNameByCatalogueId(catalogueId);
        long l1 = System.currentTimeMillis();
        log.info("功能名称:{根据目录查询病症},请求方法:{},请求URL:{},响应结果:{},接口耗时:{}",
                request.getMethod(), request.getRequestURL(), queryDiseaseNameByCatalogueId, l1 - l + "毫秒");
        return Result.success(queryDiseaseNameByCatalogueId);
    }

    /**
     * 根据目录id查询药品名称
     */
    @PostMapping("/queryDrugNameByCatalogueId/{catalogueId}")
    public Result<List<Drug>> queryDrugNameByCatalogueId(@PathVariable Integer catalogueId) {
        long l = System.currentTimeMillis();
        log.info("功能名称:{根据目录id查询药品名称},请求方法:{},请求URL:{},请求参数:{}",
                request.getMethod(), request.getRequestURL(), catalogueId);
        List<Drug> queryDrugNameByCatalogueId = mineService.queryDrugNameByCatalogueId(catalogueId);
        long l1 = System.currentTimeMillis();
        log.info("功能名称:{首页目录},请求方法:{},请求URL:{},响应结果:{},接口耗时:{}",
                request.getMethod(), request.getRequestURL(), queryDrugNameByCatalogueId, l1 - l + "毫秒");
        return Result.success(queryDrugNameByCatalogueId);
    }

    /**
     * 药品类型
     *
     * @return
     */
    @GetMapping("/queryPharmacyName")
    public Result<List<Pharmacy>> queryPharmacyName() {
        long l = System.currentTimeMillis();
        log.info("功能名称:{药品类型},请求方法:{},请求URL:{}",
                request.getMethod(), request.getRequestURL());
        List<Pharmacy> queryPharmacyName = mineService.queryPharmacyName();
        long l1 = System.currentTimeMillis();
        log.info("功能名称:{药品类型},请求方法:{},请求URL:{},响应结果:{},接口耗时:{}",
                request.getMethod(), request.getRequestURL(), queryPharmacyName, l1 - l + "毫秒");
        return Result.success(queryPharmacyName);
    }

    @PostMapping("/queryDrugByPharmacyId/{pharmacyId}")
    public Result<List<Drug>> queryDrugByPharmacyId(@PathVariable Integer pharmacyId) {
        long l = System.currentTimeMillis();
        log.info("功能名称:{根据药品类型查询药品},请求方法:{},请求URL:{},请求参数:{}",
                request.getMethod(), request.getRequestURL(), pharmacyId);
        List<Drug> queryDrugByPharmacyId = mineService.queryDrugByPharmacyId(pharmacyId);
        long l1 = System.currentTimeMillis();
        log.info("功能名称:{根据药品类型查询药品},请求方法:{},请求URL:{},响应结果:{},接口耗时:{}",
                request.getMethod(), request.getRequestURL(), queryDrugByPharmacyId, l1 - l + "毫秒");
        return Result.success(queryDrugByPharmacyId);
    }


    /**
     * 签到任务
     *
     * @param reqTask
     * @return
     */
    @PostMapping("/attendance}")
    public Result attendance(@RequestBody ReqTask reqTask) {
        String result = mineService.attendance(reqTask);
        return Result.success(result);
    }


    /**
     * 根据药品名称查询药品
     *
     * @param name
     * @return
     */
    @PostMapping("/queryMineByName")
    public Result<Drug> queryMineByName(@RequestParam String name) {
        log.info("功能名称:{根据药品类型查询药品},请求方法:{},请求URL:{},请求参数:{}",
                request.getMethod(), request.getRequestURL(), name);
        Drug result = mineService.queryMineByName(name);
        return Result.success(result);
    }


    /**
     * 医生评价服务
     *
     * @param reqEvaluate
     * @return
     */
    @PostMapping("/evaluateDoctor")
    public Result evaluateDoctor(@RequestBody ReqEvaluate reqEvaluate) {
        log.info("功能名称:{医生评价服务},请求方法:{},请求URL:{},请求参数:{}",
                request.getMethod(), request.getRequestURL(), reqEvaluate);
        mineService.evaluateDoctor(reqEvaluate);
        log.info("功能名称:{医生评价服务},请求方法:{},请求URL:{}",
                request.getMethod(), request.getRequestURL());
        return Result.success();
    }

    /**
     *
     * @param disease
     * @return
     */
    @PostMapping("/insertDisease")
    public Result insertDisease(@RequestBody Disease disease) {
        log.info("功能名称:{添加病症},请求方法:{},请求URL:{},请求参数:{}",
                request.getMethod(), request.getRequestURL(), disease);
        mineService.insertDisease(disease);
        log.info("功能名称:{添加病症},请求方法:{},请求URL:{}",
                request.getMethod(), request.getRequestURL());
        return Result.success();
    }


    /**
     * 赠送礼物
     * @param gift
     * @return
     */
    @PostMapping("/insertGift")
    public Result insertGift(@RequestBody Gift gift){
        log.info("功能名称:{赠送礼物},请求方法:{},请求URL:{},请求参数:{}",
                request.getMethod(), request.getRequestURL(), gift);
        mineService.insertGift(gift);
        log.info("功能名称:{赠送礼物},请求方法:{},请求URL:{}",
                request.getMethod(), request.getRequestURL());
        return Result.success();
    }

    @PostMapping("/insertEvaluate")
    public Result insertEvaluate(@RequestBody Evaluate evaluate){
        log.info("功能名称:{添加评价},请求方法:{},请求URL:{},请求参数:{}",
                request.getMethod(), request.getRequestURL(), evaluate);
        mineService.insertEvaluate(evaluate);
        log.info("功能名称:{添加评价},请求方法:{},请求URL:{}",
                request.getMethod(), request.getRequestURL());
        return Result.success();
    }



}
